package com.zhw.andfix.present;

import com.trello.rxlifecycle2.LifecycleProvider;

import cn.droidlover.xdroidmvp.mvp.IView;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.IModel;
import cn.droidlover.xdroidmvp.net.XApi;
import io.reactivex.Flowable;

/**
 * BasePresent
 * Created by Administrator on 2018/3/23.
 */

public abstract class BasePresent<V extends IView, LifecycleEvent> extends XPresent<V> {
    private LifecycleProvider<LifecycleEvent> provider;
    public BasePresent(V view, LifecycleProvider<LifecycleEvent> provider) {
        attachV(view);
        this.provider = provider;
    }

    public <T extends IModel> Flowable<T> composeApiFlowable(Flowable<T> flowable){
        return flowable.compose(XApi.<T>getApiTransformer())
                .compose(XApi.<T>getScheduler())
                .compose(provider.<T>bindToLifecycle());//和bindUntilEvent(ActivityEvent.DESTROY)一样效果
    }
}
